package com.ruoyi.web.controller.wfshou;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wfshou.domain.Prod;
import com.ruoyi.wfshou.service.IProdService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品类Controller
 * 
 * @author zongying
 * @date 2023-06-19
 */
@RestController
@RequestMapping("/wfshou/prod")
public class ProdController extends BaseController
{
    @Autowired
    private IProdService prodService;

    /**
     * 查询产品类列表
     */
    @PreAuthorize("@ss.hasPermi('wfshou:prod:list')")
    @GetMapping("/list")
    public TableDataInfo list(Prod prod)
    {
        startPage();
        List<Prod> list = prodService.selectProdList(prod);
        return getDataTable(list);
    }
    @GetMapping("/listAll")
    public TableDataInfo listAll()
    {
        List<Prod> list = prodService.selectProdList(null);
        return getDataTable(list);
    }
    /**
     * 导出产品类列表
     */
    @PreAuthorize("@ss.hasPermi('wfshou:prod:export')")
    @Log(title = "产品类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Prod prod)
    {
        List<Prod> list = prodService.selectProdList(prod);
        ExcelUtil<Prod> util = new ExcelUtil<Prod>(Prod.class);
        util.exportExcel(response, list, "产品类数据");
    }

    /**
     * 获取产品类详细信息
     */
    @PreAuthorize("@ss.hasPermi('wfshou:prod:query')")
    @GetMapping(value = "/{prodId}")
    public AjaxResult getInfo(@PathVariable("prodId") Long prodId)
    {
        return success(prodService.selectProdByProdId(prodId));
    }

    /**
     * 新增产品类
     */
    @PreAuthorize("@ss.hasPermi('wfshou:prod:add')")
    @Log(title = "产品类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Prod prod)
    {
        return toAjax(prodService.insertProd(prod));
    }

    /**
     * 修改产品类
     */
    @PreAuthorize("@ss.hasPermi('wfshou:prod:edit')")
    @Log(title = "产品类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Prod prod)
    {
        return toAjax(prodService.updateProd(prod));
    }

    /**
     * 删除产品类
     */
    @PreAuthorize("@ss.hasPermi('wfshou:prod:remove')")
    @Log(title = "产品类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{prodIds}")
    public AjaxResult remove(@PathVariable Long[] prodIds)
    {
        return toAjax(prodService.deleteProdByProdIds(prodIds));
    }
}
